muse-init.el

;;; muse-init.el --- Initialize Emacs Muse

;;Original Author: Michael Olson
;;Hacked by Suresh Kayamboo
;; In order to see the scripts that I use to publish my website to a
;; remote webserver, check out
;; http://www.mwolson.org/projects/SiteScripts.html.

;;; Setup

;; Add to load path
(add-to-list 'load-path "D:/soft/elisp/muse/lisp")
(add-to-list 'load-path "D:/soft/elisp/muse/experimental")

;; Initialize
(require 'outline)       ; I like outline-style faces
(require 'muse)          ; load generic module
(require 'muse-colors)   ; load coloring/font-lock module
(require 'muse-mode)     ; load authoring mode
(require 'muse-blosxom)  ; load blosxom module
(require 'muse-docbook)  ; load DocBook publishing style
(require 'muse-html)     ; load (X)HTML publishing style
(require 'muse-latex)    ; load LaTeX/PDF publishing styles
(require 'muse-texinfo)  ; load Info publishing style
(require 'muse-wiki)     ; load Wiki support
(require 'muse-xml)      ; load XML support
;;(require 'muse-message)  ; load message support (experimental)

;;+_ Add this else emacs will complain that required muse-config not supplied
(provide 'muse-init)


;; Setup projects

;; Here is an example of making a customized version of your favorite
;; publisher.  All this does is run `my-muse-blosoxm-finalize' on the
;; published file immediately after saving it.

(unless (assoc "my-blosxom" muse-publishing-styles)
 (muse-derive-style "my-blosxom" "blosxom-xhtml"
  :final 'my-muse-blosxom-finalize)

 (muse-derive-style "my-pdf" "pdf"
  :before 'my-muse-pdf-prepare-buffer)

 (muse-derive-style "my-xhtml" "xhtml"
  :header "D:/soft/elisp/include/myheader.html"
  :footer "D:/soft/elisp/include/myfooter.html"))

;; Here is my master project listing.

(setq muse-project-alist
 `(
     ("Website" ("D:/soft/elisp/wiki/html/"
                 :force-publish ("WikiIndex")
                 :default "WelcomePage")
      (:base "my-xhtml"
       :path "D:/soft/elisp/web/html"))

     ("Projects" ("D:/soft/elisp/wiki/proj/"
                  :force-publish ("WikiIndex")
                  :default "WelcomePage")
      (:base "my-xhtml"
       :path "D:/soft/elisp/web/proj"))

     ("Blog" (,@(muse-project-alist-dirs "D:/soft/elisp/wiki/sblog")
              :default "index")

      ;; Publish this directory and its subdirectories.  Arguments
      ;; are as follows.  The above `muse-project-alist-dirs' part
      ;; is also needed, using Argument 1.
      ;;
      ;;  1. Source directory
      ;;  2. Output directory
      ;;  3. Publishing style
      ,@(muse-project-alist-styles "D:/soft/elisp/wiki/sblog"
          "D:/soft/elisp/web/sblog"
          "my-blosxom"))

     ("MyNotes" ("D:/soft/elisp/wiki/notes/"
                 :force-publish ("index")
                 :default "index")
      (:base "xhtml"
       :path "D:/soft/elisp/web/notes"))


     ("Plans" ("D:/soft/elisp/wiki/plans/"
               :default "TaskPool"
               :major-mode planner-mode
               :visit-link planner-visit-link)
      (:base "planner-xhtml"
       :path "D:/soft/elisp/web/plans"))
     ))

     ;; Wiki settings
     (setq muse-wiki-interwiki-alist
      '(("PlugWiki" . "http://plug.student-orgs.purdue.edu/wiki/")
          ("EmacsWiki" . "http://www.emacswiki.org/cgi-bin/wiki/")
          ("ArchWiki" . "http://wiki.gnuarch.org/")
          ;; abbreviations
          ("CERIAS" . "http://www.cerias.purdue.edu/")
          ("PlannerMode" . "http://www.plannerlove.com/")
          ("GP2X" . "http://www.gp2x.co.uk/")
          ("UbuntuLinux" . "http://ubuntulinux.org/")
          ("PLUG" . "http://plug.student-orgs.purdue.edu/wiki/")))

     ;;; Functions

;; Turn relative links into absolute ones
(defun my-muse-pdf-make-links-absolute (str &rest ignored)
 "Make relative links absolute."
 (when str
  (save-match-data
   (if (string-match "\\`[/.]+" str)
    (replace-match "http://www.armory.com/~suresh/" nil t str)
    str))))

    ;; Make sure my interproject links become absolute when published in
;; PDFs
(defun my-muse-pdf-prepare-buffer ()
 (set (make-local-variable 'muse-publish-url-transforms)
  (cons 'my-muse-pdf-make-links-absolute muse-publish-url-transforms)))

;; Switch to the given project and prompt for a file
(defun my-muse-project-find-file (project)
 (interactive)
 (let ((muse-current-project (muse-project project)))
  (call-interactively 'muse-project-find-file)))

;; Determine whether we are publishing a certain kind of output
(defun my-muse-format-p (format)
 (let ((base (muse-get-keyword :base muse-publishing-current-style)))
  (when base (string-match format base))))

(defun my-muse-blosxom-finalize (file output-path target)
 ;;  (my-muse-prepare-entry-for-xanga output-path)
 ;; For now, do nothing.
 )

    ;; Make the current file display correctly in Xanga
;; I call this using C-c p x now.
(defun my-muse-prepare-entry-for-xanga (file)
 "Mangle FILE so that Xanga doesn't bug out, saving to X clipboard.

 If FILE is not specified, use the published version of the current file."
 (interactive
  (list
   (expand-file-name (concat (muse-page-name) muse-blosxom-extension)
    (muse-style-element
     :path (car (muse-project-applicable-styles
             buffer-file-name
             (cddr (muse-project-of-file))))))))
 (save-match-data
  (muse-with-temp-buffer
   (insert-file-contents file)
   ;; surround first line in <h3></h3>
   (goto-char (point-min))
   (insert "<h3>")
   (end-of-line)
   (insert "</h3>")
   ;; treat example regions properly
   (let (beg end)
    (while (re-search-forward "<pre[^>]*>" nil t)
     (setq beg (match-end 0))
     (setq end (if (re-search-forward "</pre>" nil 1)
                (match-beginning 0)
                (point)))
     (save-restriction
      (narrow-to-region beg end)
      ;; change initial spaces to &nbsp;
      (goto-char (point-min))
      (while (re-search-forward "^ +" nil t)
       (replace-match (apply 'concat (make-list
                                      (length (match-string 0))
                                      "&nbsp;"))))
      ;; change newline to <br />
      (goto-char (point-min))
      (while (re-search-forward "\n" nil t)
       (replace-match "<br />")))))
;; get rid of 2 spaces together and merge lines
(goto-char (point-min))
    (while (re-search-forward (concat "[" muse-regexp-blank "\n]+") nil t)
     (replace-match " "))
;; remove trailing space
(goto-char (point-min))
    (while (re-search-forward " *</p> *" nil t)
     (replace-match "</p>"))
;; make relative links work
(goto-char (point-min))
    (while (re-search-forward "href=\"[/.]+" nil t)
     (replace-match "href=\"http://www.armory.com/~suresh/" nil t))
;; copy entry to clipboard
(clipboard-kill-ring-save (point-min) (point-max)))))

    ;;; Key customizations

    (global-set-key "\C-cpl" 'muse-blosxom-new-entry)
    (global-set-key "\C-cpL" #'(lambda () (interactive)
                                (my-muse-project-find-file "Blog")))
    (global-set-key "\C-cpi" #'(lambda () (interactive)
                                (my-muse-project-find-file "Private")))
    (global-set-key "\C-cpn" #'(lambda () (interactive)
                                (my-muse-project-find-file "MyNotes")))
    (global-set-key "\C-cpp" #'(lambda () (interactive)
                                (my-muse-project-find-file "Plans")))
    (global-set-key "\C-cpr" #'(lambda () (interactive)
                                (my-muse-project-find-file "Projects")))
    (global-set-key "\C-cps" #'(lambda () (interactive)
                                (my-muse-project-find-file "Classes")))
    (global-set-key "\C-cpw" #'(lambda () (interactive)
                                (my-muse-project-find-file "Website")))
    (global-set-key "\C-cpx" 'my-muse-prepare-entry-for-xanga)

    ;;; Custom variables

    (custom-set-variables
     '(muse-blosxom-base-directory "D:/soft/elisp/wiki/sblog/")
     '(muse-colors-autogen-headings (quote outline))
     '(muse-colors-inline-image-method (quote muse-colors-use-publishing-directory))
     '(muse-html-charset-default "utf-8")
     '(muse-html-encoding-default (quote utf-8))
     '(muse-html-footer "D:/soft/elisp/include/myfooter.htmll")
     '(muse-html-header "D:/soft/elisp/include/myheader.html")
     '(muse-html-meta-content-encoding (quote utf-8))
     '(muse-html-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/common.css\" />
         <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"screen\" href=\"/screen.css\" />
         <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"print\" href=\"/print.css\" />")
     ;;'(muse-latex-header "~/personal-site/muse/header.tex")
     ;;'(muse-mode-hook (quote (flyspell-mode footnote-mode)))
     ;;'(muse-publish-comments-p t)
     ;;'(muse-publish-desc-transforms (quote (muse-wiki-publish-pretty-title muse-wiki-publish-pretty-interwiki)))
     ;;'(muse-wiki-publish-small-title-words (quote ("the" "and" "at" "on" "of" "for" "in" "an" "a" "page")))
     ;;'(muse-xhtml-footer "D:/soft/elisp/include/myfooter.html")
     ;;'(muse-xhtml-header "D:/soft/elisp/include/myheader.html")
     ;;'(muse-xhtml-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/common.css\" />
         ;;<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"screen\" href=\"/screen.css\" />
         ;;<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"print\" href=\"/print.css\" />")
     )
     (custom-set-faces
      '(muse-bad-link ((t (:foreground "DeepPink" :underline "DeepPink" :weight bold)))))





     ;;; muse-init.el ends here




